package com.photoeditor.demo.ui.widget;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.common.base.utils.DeviceUtils;
import com.photoeditor.R;

import androidx.annotation.RequiresApi;

/**
 * Created by zhangwei on 19-7-19.
 */
public class VideoForegroundView extends RelativeLayout {

    private Context mContext;

    private ImageView mImage;
    private TextView mText;

    public VideoForegroundView(Context context) {
        super(context);
        init(context);
    }

    public VideoForegroundView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public VideoForegroundView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public VideoForegroundView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    private void init(Context context) {
        this.mContext = context;

        mImage = new ImageView(context);
        LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        mImage.setLayoutParams(lp);
        addView(mImage);
        mImage.setImageResource(R.drawable.vip_video_bg);

        mText = new TextView(context);
        lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        lp.topMargin = DeviceUtils.dip2px(26f);
        mText.setLayoutParams(lp);
        mText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22);
        mText.setTypeface(Typeface.DEFAULT_BOLD);
        mText.setTextColor(Color.parseColor("#25265E"));
        addView(mText);
    }

    public void setImageResId(int resId) {
        if (resId <= 0 || mImage == null) {
            return;
        }

        mImage.setImageResource(resId);
    }

    public void setText(int resId) {
        if (resId <= 0) {
            return;
        }

        String text = mContext.getString(resId);
        setText(text);
    }

    public void setText(String text) {
        if (mText == null) {
            return;
        }

        mText.setText(text);
    }
}
